package ru.papergames.battleserver.model.battle.map;

import ru.papergames.battleserver.model.battle.GameBall;

/**
 * @author: atroshanin
 * Date: 11.04.2010
 * Time: 18:34:52
 */
public class Cell {

    private CellState state = CellState.FREE;
    private final int x;
    private final int y;
    private GameBall gameBall;
    private Obstacle obstacle;

    public Cell(int x, int y) {
        this.x = x;
        this.y = y;
    }

    public boolean isFree() {
        return state == CellState.FREE;
    }

    public int getX() {
        return x;
    }

    public int getY() {
        return y;
    }

    public CellState getState() {
        return state;
    }

    public void setState(CellState state) {
        this.state = state;
    }

    public Obstacle getObstacle() {
        return obstacle;
    }

    void setObstacle(Obstacle obstacle) {
        this.obstacle = obstacle;
    }

    public GameBall getGameBall() {
        return gameBall;
    }

    void setGameBall(GameBall gameBall) {
        this.gameBall = gameBall;
        this.gameBall.setCell(this);
    }

    void removeGameBall() {
        this.gameBall = null;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) {
            return true;
        }
        if (o == null || getClass() != o.getClass()) {
            return false;
        }

        Cell cell = (Cell) o;

        return x == cell.x && y == cell.y;

    }

    @Override
    public int hashCode() {
        int result = x;
        result = 31 * result + y;
        return result;
    }

    @Override
    public String toString() {
        return "Cell{" +
                "x=" + x +
                ", y=" + y +
                '}';
    }
}
